#pragma once
#include "Loader.h"
#include "ModelLoaderStructs.h"

namespace Loading{
	class ModelLoader : public Loader<Graphics::Model>{
	public:
		ModelLoader();

		void setModelFilename(std::string &filename) { m_filename = Core::GeneralSettings::findFilePath(filename); }

		boost::shared_ptr<Graphics::Model> load();
	private:
		bool processAnimations();
		bool processModels();
		bool processAnimationPart(	unsigned int sourceId, 
									std::map<Graphics::AnimationSampler::AnimationSamplingType,std::vector<float>>& samplerData,
									std::map<Graphics::AnimationSampler::AnimationSamplingType,unsigned int>& samplerStrides);

		void cleanUp();
		std::ifstream m_inputStream;

		char* vertBuffer;
		char* indBuffer;

		// Model
		outputTextureData* 			textures;
		outputEffectData*			effects;
		outputSubMesh* 				submeshes;
		outputModelHeader*			modelHeaders;
		outputVertLayout* 			layoutHeaders;
		outputVertLayoutElement* 	layoutElements;

		// Animation
		outputController* 			controllers;
		outputJoint*				joints;
		outputAnimation*			animations;
		outputAnimationSampler* 	animationSamplers;
		outputAnimationClip*		animationClips;
		outputAnimationSource*		animationSources;
		float*						animationFloats;
		unsigned int*				animationUints;

		DataHeader					dataHeader;

		std::string					m_filename;

		std::vector<std::pair<std::string,unsigned int>> m_clipsAdded;
		std::vector<Graphics::ModelPtr> m_models;
	};
}